package com.zqxq.lottery.api.controller;

import com.zqxq.common.constant.Result;
import com.zqxq.common.enums.CodeEnum;
import com.zqxq.lottery.api.feign.LotteryServerFeignClient;
import com.zqxq.lottery.entity.vo.sys.SysBannerVO;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/22 11:01
 */
@Api(value = "banner广告接口",tags = "banner广告接口")
@RestController
@Slf4j
@RequestMapping(value = "/banner", produces = "application/json")
public class BannerController {

    @Autowired
    private LotteryServerFeignClient lotteryServerFeignClient;

    /***********************************************banner*******************************************************/
    @ApiOperation("获取banner列表")
    @PostMapping("/queryList")
    public Result<List<SysBannerVO>> queryList(HttpServletRequest request, @ApiParam(value = "banner类型 0：首页顶部 1：首页中部 2：个人中心 3：弹窗 4:资讯首页",required = false) @RequestParam(defaultValue = "0") Integer type){
        String appKey = request.getParameter("appKey");
        return lotteryServerFeignClient.queryBannerList(appKey,type);
    }

    @ApiOperation("保存banner点击数")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键", required = true, paramType = "query", dataType = "Long")
    })
    @PostMapping("/saveClickNum")
    public Result<List<SysBannerVO>> saveBannerClickNum(Long id){
        if(id == null){
            return new Result(CodeEnum.FAIL_100002.getCode(), CodeEnum.FAIL_100002.getMsg());
        }
        return lotteryServerFeignClient.saveBannerClickNum(id);
    }
}
